Skip to content

Conversation

@esavin
Copy link
Contributor

@esavin esavin commented Oct 31, 2025

Hello. I need to work with probability values for OnlineRecognizer in my Android application, so I expose ys_probs array to JNI and implemented it in Java and in Kotlin API.

Summary by CodeRabbit

  • New Features
    • Recognition results now include additional probability data for enhanced confidence analysis.
    • New data accessors added to recognition result objects across Java and Kotlin language bindings.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 31, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Walkthrough

The changes extend the OnlineRecognizerResult class across Java, JNI, and Kotlin API bindings by adding a new ysProbs field containing a float array of probabilities. The field is wired into constructors, getters, and the result retrieval pipeline consistently across all three implementations.

Changes

Cohort / File(s) Summary
Java API Updates
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizer.java, sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizerResult.java
Added ysProbs field to OnlineRecognizerResult. Constructor signature updated from three to four parameters. getResult() retrieves the fourth array element and constructs result with ysProbs. New public getter getYsProbs() added.
JNI Binding
sherpa-onnx/jni/online-recognizer.cc
Extended JNI result array from size 3 to size 4 to accommodate ys_probs vector. Fourth element populated as a jfloatArray and placed at index 3 in the returned object array.
Kotlin API Updates
sherpa-onnx/kotlin-api/OnlineRecognizer.kt
Added ysProbs: FloatArray field to OnlineRecognizerResult data class. Updated getResult() to read and pass the fourth element from the object array.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant OnlineRecognizer
    participant JNI
    participant NativeLib as Native Lib
    participant Result

    Caller->>OnlineRecognizer: getResult(stream)
    OnlineRecognizer->>JNI: Call native method
    JNI->>NativeLib: Invoke C++ recognition
    NativeLib->>Result: Compute text, tokens, timestamps, ys_probs
    Result-->>NativeLib: Return recognition data
    NativeLib-->>JNI: Return object array [text, tokens, timestamps, ys_probs]
    JNI->>JNI: Extract 4 elements from array
    JNI->>OnlineRecognizer: Return jObjectArray
    OnlineRecognizer->>OnlineRecognizer: Construct OnlineRecognizerResult(text, tokens, timestamps, ysProbs)
    OnlineRecognizer-->>Caller: Return result with ysProbs field
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Changes follow a consistent, repetitive pattern across Java, JNI, and Kotlin bindings
  • Addition is straightforward (new field in data structure)
  • Minimal logic density

Areas requiring attention:

  • Verify consistency of the fourth element placement across all three implementations (JNI, Java, Kotlin)
  • Confirm that ysProbs is correctly populated at the native level and properly marshalled through JNI boundaries
  • Ensure no existing callers of OnlineRecognizerResult constructor break due to signature change

Poem

🐰 Four floats now dance in the result array,
Where ys_probs join their siblings at play,
From native lands through JNI's bridge they flow,
Java and Kotlin both now know,
The fuller truth the recognizer did grow! 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Expose ys probs to JNI, Kotlin and Java API" accurately describes the main changes across the pull request. The PR modifies files in three distinct API layers (JNI C++ code, Java API, and Kotlin API) to expose the ys_probs field, making it accessible to callers. The title is specific and concrete, mentioning both the feature being exposed (ys probs) and the APIs affected, which aligns directly with the changes summarized in the raw summary. The title is neither vague nor overly broad, and it provides clear context for understanding the primary objective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
sherpa-onnx/jni/online-recognizer.cc (1)

412-415: LGTM: ys_probs array properly created and populated.

The JNI code correctly creates and populates the ys_probs float array using standard JNI patterns consistent with the existing timestamps array handling.

However, consider adding documentation (either in code comments or external documentation) explaining what the ys_probs values represent, their expected range, and how they correspond to the tokens.

sherpa-onnx/kotlin-api/OnlineRecognizer.kt (1)

86-86: LGTM: ysProbs field added to data class.

The new field is correctly typed and positioned. Note that like timestamps, FloatArray uses referential equality in Kotlin data classes, which means two OnlineRecognizerResult instances with identical probability arrays won't be considered equal by the generated equals() method. This is consistent with the existing design.

Consider adding KDoc documentation to explain what ysProbs represents.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0f335c and 82819c3.

📒 Files selected for processing (4)
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizer.java (1 hunks)
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizerResult.java (2 hunks)
  • sherpa-onnx/jni/online-recognizer.cc (2 hunks)
  • sherpa-onnx/kotlin-api/OnlineRecognizer.kt (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
sherpa-onnx/kotlin-api/OnlineRecognizer.kt (1)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizerResult.java (1)
  • OnlineRecognizerResult (5-34)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizerResult.java (1)
sherpa-onnx/kotlin-api/OnlineRecognizer.kt (1)
  • text (82-88)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizer.java (1)
sherpa-onnx/kotlin-api/OnlineRecognizer.kt (1)
  • text (82-88)
🔇 Additional comments (5)
sherpa-onnx/jni/online-recognizer.cc (1)

387-389: LGTM: Array size and documentation updated correctly.

The array size has been properly increased to accommodate the new ys_probs field, and the comment accurately documents the structure of the result array.

sherpa-onnx/kotlin-api/OnlineRecognizer.kt (1)

128-130: LGTM: Result extraction and construction updated correctly.

The code properly extracts the ysProbs array from the fourth element and constructs the result with all four fields, maintaining consistency with the JNI layer.

sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizerResult.java (2)

9-16: LGTM: Field and constructor properly implemented.

The ysProbs field is correctly declared as final, and the constructor properly assigns it. The implementation follows the same pattern as the existing timestamps field.


30-32: LGTM: Getter method follows existing pattern.

The getter is correctly implemented and follows the same pattern as getTimestamps(). Note that it returns the internal array directly, which allows external modification, but this is consistent with the existing design.

sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OnlineRecognizer.java (1)

69-70: LGTM: Result extraction and construction updated correctly.

The code properly extracts the ysProbs array from the native result and constructs OnlineRecognizerResult with the updated four-parameter signature, maintaining consistency with the JNI layer.

@esavin esavin changed the title Expose ys probs Expose ys probs to JNI, Kotlin and Java API Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant